<template>
  <div class="components-container">
    <sweet-modal ref="dialog" class="dialog" :sweetModalMaxWidth="1000">
      <h3>{{ order }}</h3>
      <!-- 生成联办单(金华) -->
      <div v-if="GenerateJointSingle == 10" class="seecSingle-box" style="overflow: auto;">
        <fieldset class="layui-elem-field layui-field-title">
          <legend style="font-weight: bold;">殡仪馆</legend>
          <div>
            <el-checkbox v-model="funeralParlour">火化手续办理</el-checkbox>
          </div>
        </fieldset>
        <fieldset class="layui-elem-field layui-field-title">
          <legend style="font-weight: bold;">公安</legend>
          <div>
            <el-checkbox v-model="police">户口注销后需要打印户口注销证明的由公安机关邮寄至申请人</el-checkbox>
          </div>
        </fieldset>
        <fieldset class="layui-elem-field layui-field-title">
          <legend style="font-weight: bold;">殡管所</legend>
          <div>
            <el-radio-group v-model="ashTrack">
              <el-radio v-for="(item, index) in ashTrackList" :key="index" :label="item.CodeValue">{{ item.CodeName }}</el-radio>
            </el-radio-group>
          </div>
        </fieldset>
        <fieldset class="layui-elem-field layui-field-title">
          <legend style="font-weight: bold;">社保</legend>
          <div>
            <el-checkbox v-model="socialMultiAll" @change="socialMultiAllChange">死亡人员的养老保险关系终止办理</el-checkbox>
            <el-checkbox-group v-model="socialMulti" @change="socialMultiChange">
              <el-checkbox v-for="(item, index) in socialMultiList" :key="index" :label="item.CodeValue">{{ item.CodeName }}</el-checkbox>
            </el-checkbox-group>
          </div>
        </fieldset>
        <fieldset class="layui-elem-field layui-field-title">
          <legend style="font-weight: bold;">医保</legend>
          <div>
            <el-checkbox v-model="deadChargeAll" @change="deadChargeAllChange">死亡人员医疗保险事项办理</el-checkbox>
            <el-checkbox-group v-model="deadCharge" @change="deadChargeChange">
              <el-checkbox v-for="(item, index) in deadChargeList" :key="index" :label="item.CodeValue">{{ item.CodeName }}</el-checkbox>
            </el-checkbox-group>
          </div>
        </fieldset>
        <fieldset class="layui-elem-field layui-field-title">
          <legend style="font-weight: bold;">公积金</legend>
          <div>
            <el-checkbox v-model="accumulationFund">死亡人员住房公积金结算</el-checkbox>
          </div>
        </fieldset>
        <fieldset class="layui-elem-field layui-field-title">
          <legend style="font-weight: bold;">社保</legend>
          <div>
            <el-radio-group v-model="socialRadio">
              <el-radio v-for="(item, index) in socialRadioList" :key="index" :label="item.CodeValue">{{ item.CodeName }}</el-radio>
            </el-radio-group>
            <!-- <el-checkbox-group v-model="socialRadio" :max="1">
              <el-checkbox v-for="(item,index) in socialRadioList" :key="index" :label="item.CodeValue">{{item.CodeName}}</el-checkbox>
            </el-checkbox-group>-->
          </div>
        </fieldset>
      </div>
      <!-- 生成联办单(舟山) -->
      <div v-if="GenerateJointSingle == 20" class="seecSingle-box" style="overflow: auto;">
        <fieldset class="layui-elem-field layui-field-title">
          <legend style="font-weight: bold;">医保</legend>
          <div>
            <el-checkbox v-model="deadChargeAll" @change="deadChargeAllChange">死亡人员医疗保险事项办理(在医保关系终止前请先办理医疗费用结报)</el-checkbox>
            <el-checkbox-group v-model="deadCharge" @change="deadChargeChange">
              <el-checkbox v-for="(item, index) in deadChargeList" :key="index" :label="item.CodeValue">{{ item.CodeName }}</el-checkbox>
            </el-checkbox-group>
          </div>
        </fieldset>
        <fieldset class="layui-elem-field layui-field-title">
          <legend style="font-weight: bold;">公积金</legend>
          <div>
            <el-checkbox v-model="accumulationFund">死亡或被宣告死亡人员有公积金的提取住房公积金</el-checkbox>
          </div>
        </fieldset>
        <fieldset class="layui-elem-field layui-field-title">
          <legend style="font-weight: bold;">社保</legend>
          <div>
            <!-- <el-checkbox v-model="socialMultiAll" @change="socialMultiAllChange">
            死亡人员的养老保险关系终止办理</el-checkbox>-->
            <el-checkbox-group v-model="socialMulti" @change="socialMultiChange">
              <el-checkbox v-for="(item, index) in socialMultiList" :key="index" :label="item.CodeValue">{{ item.CodeName }}</el-checkbox>
            </el-checkbox-group>
          </div>
        </fieldset>
        <fieldset class="layui-elem-field layui-field-title">
          <legend style="font-weight: bold;">殡管所</legend>
          <div>
            <el-radio-group v-model="ashTrack">
              <el-radio v-for="(item, index) in ashTrackList" :key="index" :label="item.CodeValue">{{ item.CodeName }}</el-radio>
            </el-radio-group>
          </div>
        </fieldset>
        <fieldset class="layui-elem-field layui-field-title">
          <legend style="font-weight: bold;">公安</legend>
          <div>
            <el-checkbox v-model="police">死亡人员户口注销(公安机关在公民死亡30日后一个工作日注销该公民户籍如需延长和当地派出所联系)</el-checkbox>
          </div>
        </fieldset>
      </div>
      <div class="layui-form-item btnCenter">
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="primary" @click="submit">生成联办单</el-button>
      </div>
    </sweet-modal>
    <signturePanel ref="pdf"></signturePanel>
  </div>
</template>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";

.el-button + .el-button {
  margin-left: 0;
}

.longertext {
  width: 450px;
}

.sweet-btn {
  margin-top: 20px;
}
</style>
<script>
import apiBase from "@/api/apiBase.js"
// import DoGWQ_StartSign from "@/utils/signaturePanel.js"
import signturePanel from "@/components/signturePanel"
import sweetModal from "@/components/sweetModal"
import { manage } from "@/mixins/managePage.js"
import { formatDate, timeStringToDate } from "@/utils/date.js"
export default {
  mixins: [manage],
  data() {
    return {
      funeralParlour: false,
      police: false,
      ashTrack: [],
      ashTrackList: [],
      socialRadio: [],
      socialRadioList: [],
      socialMulti: [],
      socialMultiAll: null,
      socialMultiList: [],
      isIndeterminate: false,
      accumulationFund: false,
      deadChargeAll: [],
      deadCharge: [],
      deadChargeList: [],
      order: null,
      id: null,
      GenerateJointSingle: null,
      isHaveSign: null
    }
  },
  methods: {
    open(order, id) {
      this.dataRepeat()
      this.order = order
      switch (this.order) {
        case "生成联办单":
          this.id = id
          this.$refs.dialog.open()
          break
        default:
      }
    },
    submit() {
      switch (this.order) {
        case "生成联办单":
          this.addSeecSingle()
          break
        default:
      }
    },
    // 生成联办但
    addSeecSingle() {
      let data = {
        REGID: this.id,
        Funeral: this.funeralParlour ? "B" : "A",
        Police: this.police ? "B" : "A",
        FuneralHome: this.ashTrack,
        SocialSecurity: `${this.socialMulti.join(",")}${
          this.socialRadio.length > 0 && this.socialMulti.length > 0 ? "," : ""
        }${this.socialRadio}`,
        MedicalInsurance: this.deadCharge.join(","),
        AccumulationFund: this.accumulationFund ? "B" : "A"
      }
      apiBase.DoService(
        data,
        apiBase.getApiAdress().JointDeclareProjct.UpdateAddJpr,
        res => {
          if (this.isHaveSign) {
            this.$refs.pdf.DoGWQ_StartSign(
              res.data.content.PDFNAME,
              "D:\\hw.xml",
              "0,1,150,120|1,1,150,120",
              "test",
              60,
              this.id
            )
          }
          this.$message({
            type: "success",
            message: "生成联办单成功"
          })
          this.$refs.dialog.close()
        }
      )
    },
    //数据重置
    dataRepeat() {
      this.funeralParlour = false
      this.police = false
      this.ashTrack = []
      this.socialRadio = []
      this.socialMulti = []
      this.socialMultiAll = null
      this.deadChargeAll = null
      this.accumulationFund = false
      this.deadCharge = []
    },
    closeDialog() {
      this.$refs.dialog.close()
    },
    socialMultiAllChange(val) {
      if (val) {
        this.socialMulti = this.socialMultiList.map(item => {
          return item.CodeValue
        })
      } else {
        this.socialMulti = []
      }
    },
    socialMultiChange(value) {
      let checkedCount = value.length
      this.socialMultiAll = checkedCount > 0
    },
    deadChargeAllChange(val) {
      if (val) {
        this.deadCharge = this.deadChargeList.map(item => {
          return item.CodeValue
        })
      } else {
        this.deadCharge = []
      }
    },
    deadChargeChange(value) {
      let checkedCount = value.length
      this.deadChargeAll = checkedCount > 0
    }
  },
  created() {
    apiBase.DoService(
      { type: "骨灰去向殡管所" },
      apiBase.getApiAdress().Code.GetType,
      res => {
        this.ashTrackList = res.data.content
      }
    )
    apiBase.DoService(
      { type: "社保多选" },
      apiBase.getApiAdress().Code.GetType,
      res => {
        this.socialMultiList = res.data.content
      }
    )
    apiBase.DoService(
      { type: "社保单选" },
      apiBase.getApiAdress().Code.GetType,
      res => {
        this.socialRadioList = res.data.content
      }
    )
    apiBase.DoService(
      { type: "医保" },
      apiBase.getApiAdress().Code.GetType,
      res => {
        this.deadChargeList = res.data.content
      }
    )
    // 是否有电子签名设备
    apiBase.DoService({}, apiBase.getApiAdress().Param.GetIsHaveSign, res => {
      this.isHaveSign = res.data.content
    })
    apiBase.DoService(
      {},
      apiBase.getApiAdress().Param.GetGenerateJointSingle,
      res => {
        this.GenerateJointSingle = res.data.content
      }
    )
  },
  components: {
    sweetModal,
    signturePanel
  }
}
</script>
